

<!DOCTYPE html>
<html class="writer-html5" lang="zh" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>链接提取器 &mdash; Scrapy 2.3.0 文档</title>
  

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster.custom.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster.bundle.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-shadow.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-punk.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-noir.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-light.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/tooltipster-sideTip-borderless.min.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/micromodal.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/sphinx_rtd_theme.css" type="text/css" />

  
  
  
  

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script src="../_static/js/hoverxref.js"></script>
        <script src="../_static/js/tooltipster.bundle.min.js"></script>
        <script src="../_static/js/micromodal.min.js"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="设置" href="settings.html" />
    <link rel="prev" title="请求和响应" href="request-response.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home" alt="Documentation Home"> Scrapy
          

          
          </a>

          
            
            
              <div class="version">
                2.3
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">第一步</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intro/overview.html">Scrapy一目了然</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/install.html">安装指南</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/tutorial.html">Scrapy 教程</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro/examples.html">实例</a></li>
</ul>
<p class="caption"><span class="caption-text">基本概念</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="commands.html">命令行工具</a></li>
<li class="toctree-l1"><a class="reference internal" href="spiders.html">蜘蛛</a></li>
<li class="toctree-l1"><a class="reference internal" href="selectors.html">选择器</a></li>
<li class="toctree-l1"><a class="reference internal" href="items.html">项目</a></li>
<li class="toctree-l1"><a class="reference internal" href="loaders.html">项目加载器</a></li>
<li class="toctree-l1"><a class="reference internal" href="shell.html">Scrapy shell</a></li>
<li class="toctree-l1"><a class="reference internal" href="item-pipeline.html">项目管道</a></li>
<li class="toctree-l1"><a class="reference internal" href="feed-exports.html">Feed 导出</a></li>
<li class="toctree-l1"><a class="reference internal" href="request-response.html">请求和响应</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">链接提取器</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#module-scrapy.linkextractors">链接提取器引用</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#module-scrapy.linkextractors.lxmlhtml">LxmlLinkExtractor</a></li>
<li class="toctree-l3"><a class="reference internal" href="#module-scrapy.link">链接</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="settings.html">设置</a></li>
<li class="toctree-l1"><a class="reference internal" href="exceptions.html">例外情况</a></li>
</ul>
<p class="caption"><span class="caption-text">内置服务</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="logging.html">登录</a></li>
<li class="toctree-l1"><a class="reference internal" href="stats.html">统计数据集合</a></li>
<li class="toctree-l1"><a class="reference internal" href="email.html">发送电子邮件</a></li>
<li class="toctree-l1"><a class="reference internal" href="telnetconsole.html">远程登录控制台</a></li>
<li class="toctree-l1"><a class="reference internal" href="webservice.html">Web服务</a></li>
</ul>
<p class="caption"><span class="caption-text">解决具体问题</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">常见问题</a></li>
<li class="toctree-l1"><a class="reference internal" href="debug.html">调试spiders</a></li>
<li class="toctree-l1"><a class="reference internal" href="contracts.html">蜘蛛合约</a></li>
<li class="toctree-l1"><a class="reference internal" href="practices.html">常用做法</a></li>
<li class="toctree-l1"><a class="reference internal" href="broad-crawls.html">宽爬行</a></li>
<li class="toctree-l1"><a class="reference internal" href="developer-tools.html">使用浏览器的开发人员工具进行抓取</a></li>
<li class="toctree-l1"><a class="reference internal" href="dynamic-content.html">选择动态加载的内容</a></li>
<li class="toctree-l1"><a class="reference internal" href="leaks.html">调试内存泄漏</a></li>
<li class="toctree-l1"><a class="reference internal" href="media-pipeline.html">下载和处理文件和图像</a></li>
<li class="toctree-l1"><a class="reference internal" href="deploy.html">部署蜘蛛</a></li>
<li class="toctree-l1"><a class="reference internal" href="autothrottle.html">AutoThrottle 扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="benchmarking.html">标杆管理</a></li>
<li class="toctree-l1"><a class="reference internal" href="jobs.html">作业：暂停和恢复爬行</a></li>
<li class="toctree-l1"><a class="reference internal" href="coroutines.html">协同程序</a></li>
<li class="toctree-l1"><a class="reference internal" href="asyncio.html">asyncio</a></li>
</ul>
<p class="caption"><span class="caption-text">扩展Scrapy</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="architecture.html">体系结构概述</a></li>
<li class="toctree-l1"><a class="reference internal" href="downloader-middleware.html">下载器中间件</a></li>
<li class="toctree-l1"><a class="reference internal" href="spider-middleware.html">蜘蛛中间件</a></li>
<li class="toctree-l1"><a class="reference internal" href="extensions.html">扩展</a></li>
<li class="toctree-l1"><a class="reference internal" href="api.html">核心API</a></li>
<li class="toctree-l1"><a class="reference internal" href="signals.html">信号</a></li>
<li class="toctree-l1"><a class="reference internal" href="exporters.html">条目导出器</a></li>
</ul>
<p class="caption"><span class="caption-text">其余所有</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../news.html">发行说明</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributing.html">为 Scrapy 贡献</a></li>
<li class="toctree-l1"><a class="reference internal" href="../versioning.html">版本控制和API稳定性</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Scrapy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
        
      <li>链接提取器</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="link-extractors">
<span id="topics-link-extractors"></span><h1>链接提取器<a class="headerlink" href="#link-extractors" title="永久链接至标题">¶</a></h1>
<p>链接提取器是从响应中提取链接的对象。</p>
<p>这个 <code class="docutils literal notranslate"><span class="pre">__init__</span></code> 方法 <a class="reference internal" href="#scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor" title="scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor"><code class="xref py py-class docutils literal notranslate"><span class="pre">LxmlLinkExtractor</span></code></a> 获取确定可以提取哪些链接的设置。 <a class="reference internal" href="#scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor.extract_links" title="scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor.extract_links"><code class="xref py py-class docutils literal notranslate"><span class="pre">LxmlLinkExtractor.extract_links</span></code></a> 返回匹配的列表 <a class="reference internal" href="#scrapy.link.Link" title="scrapy.link.Link"><code class="xref py py-class docutils literal notranslate"><span class="pre">Link</span></code></a> 对象来自 <a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">Response</span></code></a> 对象。</p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:block; text-align:center;"
     data-ad-layout="in-article"
     data-ad-format="fluid"
     data-ad-client="ca-pub-1466963416408457"
     data-ad-slot="8850786025"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
<p>链接提取器用于 <a class="reference internal" href="spiders.html#scrapy.spiders.CrawlSpider" title="scrapy.spiders.CrawlSpider"><code class="xref py py-class docutils literal notranslate"><span class="pre">CrawlSpider</span></code></a> 蜘蛛穿过一组 <a class="reference internal" href="spiders.html#scrapy.spiders.Rule" title="scrapy.spiders.Rule"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rule</span></code></a> 物体。</p>
<p>您也可以在普通的spider中使用链接提取器。例如，可以实例化 <a class="reference internal" href="#scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor" title="scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor"><code class="xref py py-class docutils literal notranslate"><span class="pre">LinkExtractor</span></code></a> 并从spider回调中使用它：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">link</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">link_extractor</span><span class="o">.</span><span class="n">extract_links</span><span class="p">(</span><span class="n">response</span><span class="p">):</span>
        <span class="k">yield</span> <span class="n">Request</span><span class="p">(</span><span class="n">link</span><span class="o">.</span><span class="n">url</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">parse</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="module-scrapy.linkextractors">
<span id="link-extractor-reference"></span><span id="topics-link-extractors-ref"></span><h2>链接提取器引用<a class="headerlink" href="#module-scrapy.linkextractors" title="永久链接至标题">¶</a></h2>
<p>链接提取器类是 <a class="reference internal" href="#scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor" title="scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor"><code class="xref py py-class docutils literal notranslate"><span class="pre">scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor</span></code></a> . 为了方便起见，它也可以作为 <code class="docutils literal notranslate"><span class="pre">scrapy.linkextractors.LinkExtractor</span></code> ：：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">scrapy.linkextractors</span> <span class="kn">import</span> <span class="n">LinkExtractor</span>
</pre></div>
</div>
<div class="section" id="module-scrapy.linkextractors.lxmlhtml">
<span id="lxmllinkextractor"></span><h3>LxmlLinkExtractor<a class="headerlink" href="#module-scrapy.linkextractors.lxmlhtml" title="永久链接至标题">¶</a></h3>
<dl class="py class">
<dt id="scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor">
<em class="property">class </em><code class="sig-prename descclassname">scrapy.linkextractors.lxmlhtml.</code><code class="sig-name descname">LxmlLinkExtractor</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">allow</span><span class="o">=</span><span class="default_value">()</span></em>, <em class="sig-param"><span class="n">deny</span><span class="o">=</span><span class="default_value">()</span></em>, <em class="sig-param"><span class="n">allow_domains</span><span class="o">=</span><span class="default_value">()</span></em>, <em class="sig-param"><span class="n">deny_domains</span><span class="o">=</span><span class="default_value">()</span></em>, <em class="sig-param"><span class="n">deny_extensions</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">restrict_xpaths</span><span class="o">=</span><span class="default_value">()</span></em>, <em class="sig-param"><span class="n">restrict_css</span><span class="o">=</span><span class="default_value">()</span></em>, <em class="sig-param"><span class="n">tags</span><span class="o">=</span><span class="default_value">'a', 'area'</span></em>, <em class="sig-param"><span class="n">attrs</span><span class="o">=</span><span class="default_value">'href'</span></em>, <em class="sig-param"><span class="n">canonicalize</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">unique</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">process_value</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">strip</span><span class="o">=</span><span class="default_value">True</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/scrapy/linkextractors/lxmlhtml.html#LxmlLinkExtractor"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor" title="永久链接至目标">¶</a></dt>
<dd><p>LXMLlinkextractor是推荐的带有便捷过滤选项的链接提取程序。它是使用LXML的健壮的HTMLParser实现的。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>allow</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- （绝对）URL必须匹配才能提取的单个正则表达式（或正则表达式列表）。如果没有给定（或为空），它将匹配所有链接。</p></li>
<li><p><strong>deny</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 一个单独的正则表达式（或正则表达式的列表），（绝对）URL必须匹配才能被排除（即不提取）。它优先于 <code class="docutils literal notranslate"><span class="pre">allow</span></code> 参数。如果未给定（或为空），则不会排除任何链接。</p></li>
<li><p><strong>allow_domains</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 包含用于提取链接的域的单个值或字符串列表。</p></li>
<li><p><strong>deny_domains</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 包含域的单个值或字符串列表，这些域不会被视为提取链接的域。</p></li>
<li><p><strong>deny_extensions</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 提取链接时应忽略的包含扩展名的字符串的单个值或列表。如果未给出，则默认为 <code class="xref py py-data docutils literal notranslate"><span class="pre">scrapy.linkextractors.IGNORED_EXTENSIONS</span></code> .  .. 版本更改：：2.0 <code class="xref py py-data docutils literal notranslate"><span class="pre">IGNORED_EXTENSIONS</span></code> 现在包括 <code class="docutils literal notranslate"><span class="pre">7z</span></code> ， <code class="docutils literal notranslate"><span class="pre">7zip</span></code> ， <code class="docutils literal notranslate"><span class="pre">apk</span></code> ， <code class="docutils literal notranslate"><span class="pre">bz2</span></code> ， <code class="docutils literal notranslate"><span class="pre">cdr</span></code> ， <code class="docutils literal notranslate"><span class="pre">dmg</span></code> ， <code class="docutils literal notranslate"><span class="pre">ico</span></code> ， <code class="docutils literal notranslate"><span class="pre">iso</span></code> ， <code class="docutils literal notranslate"><span class="pre">tar</span></code> ， <code class="docutils literal notranslate"><span class="pre">tar.gz</span></code> ， <code class="docutils literal notranslate"><span class="pre">webm</span></code> 和 <code class="docutils literal notranslate"><span class="pre">xz</span></code> .</p></li>
<li><p><strong>restrict_xpaths</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 是一个xpath（或xpath的列表），它定义响应中应该从中提取链接的区域。如果给定，则只扫描由这些xpath选择的文本中的链接。见下面的例子。</p></li>
<li><p><strong>restrict_css</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 一个CSS选择器（或选择器列表），它定义响应中应该从中提取链接的区域。行为与 <code class="docutils literal notranslate"><span class="pre">restrict_xpaths</span></code> .</p></li>
<li><p><strong>restrict_text</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 链接文本必须匹配才能提取的单个正则表达式（或正则表达式列表）。如果没有给定（或为空），它将匹配所有链接。如果给出了一个正则表达式列表，那么如果链接与至少一个匹配，则将提取该链接。</p></li>
<li><p><strong>tags</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.9)"><em>str</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 提取链接时要考虑的标记或标记列表。默认为 <code class="docutils literal notranslate"><span class="pre">('a',</span> <span class="pre">'area')</span></code> .</p></li>
<li><p><strong>attrs</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(在 Python v3.9)"><em>list</em></a>) -- 在查找要提取的链接时应考虑的属性或属性列表（仅适用于在 <code class="docutils literal notranslate"><span class="pre">tags</span></code> 参数）。默认为 <code class="docutils literal notranslate"><span class="pre">('href',)</span></code></p></li>
<li><p><strong>canonicalize</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.9)"><em>bool</em></a>) -- 规范化每个提取的URL（使用w3lib.url.canonicalize_url）。默认为 <code class="docutils literal notranslate"><span class="pre">False</span></code> . 请注意，规范化URL用于重复检查；它可以更改服务器端可见的URL，因此对于使用规范化URL和原始URL的请求，响应可能不同。如果您使用linkextractor跟踪链接，那么保持默认链接更为可靠。 <code class="docutils literal notranslate"><span class="pre">canonicalize=False</span></code> .</p></li>
<li><p><strong>unique</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.9)"><em>bool</em></a>) -- 是否对提取的链接应用重复筛选。</p></li>
<li><p><strong>process_value</strong> (<a class="reference external" href="https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable" title="(在 Python v3.9)"><em>collections.abc.Callable</em></a>) -- 一种函数，接收从扫描的标记和属性中提取的每个值，并能修改该值并返回一个新值，或返回 <code class="docutils literal notranslate"><span class="pre">None</span></code> 完全忽略链接。如果没有给出， <code class="docutils literal notranslate"><span class="pre">process_value</span></code> 默认为 <code class="docutils literal notranslate"><span class="pre">lambda</span> <span class="pre">x:</span> <span class="pre">x</span></code> .  …highlight：：html例如，要从此代码中提取链接，请执行以下操作：：&lt;a href=“javascript:gotopage（'../other/page.html'）；return false“&gt;link text.&lt;a&gt;。highlight:：python您可以在 <code class="docutils literal notranslate"><span class="pre">process_value</span></code> ：：def process_value（value）：m=re.search（“<a class="reference external" href="javascript:gotopage">javascript:gotopage</a>（'（.*？）'”，value）如果m:返回m.group（1）</p></li>
<li><p><strong>strip</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.9)"><em>bool</em></a>) -- 是否从提取的属性中删除空白。根据HTML5标准，必须从 <code class="docutils literal notranslate"><span class="pre">href</span></code> 属性 <code class="docutils literal notranslate"><span class="pre">&lt;a&gt;</span></code> ， <code class="docutils literal notranslate"><span class="pre">&lt;area&gt;</span></code> 还有许多其他元素， <code class="docutils literal notranslate"><span class="pre">src</span></code> 属性 <code class="docutils literal notranslate"><span class="pre">&lt;img&gt;</span></code> ， <code class="docutils literal notranslate"><span class="pre">&lt;iframe&gt;</span></code> 元素等，因此linkextractor默认情况下会删除空格字符。集合 <code class="docutils literal notranslate"><span class="pre">strip=False</span></code> 关闭它（例如，如果从允许前导/尾随空格的元素或属性中提取URL）。</p></li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt id="scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor.extract_links">
<code class="sig-name descname">extract_links</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">response</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/scrapy/linkextractors/lxmlhtml.html#LxmlLinkExtractor.extract_links"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#scrapy.linkextractors.lxmlhtml.LxmlLinkExtractor.extract_links" title="永久链接至目标">¶</a></dt>
<dd><p>返回的列表 <a class="reference internal" href="#scrapy.link.Link" title="scrapy.link.Link"><code class="xref py py-class docutils literal notranslate"><span class="pre">Link</span></code></a> 来自指定的 <a class="reference internal" href="request-response.html#scrapy.http.Response" title="scrapy.http.Response"><code class="xref py py-class docutils literal notranslate"><span class="pre">response</span></code></a> .</p>
<p>仅与传递给 <code class="docutils literal notranslate"><span class="pre">__init__</span></code> 返回链接提取器的方法。</p>
<p>重复链接被省略。</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-scrapy.link">
<span id="link"></span><h3>链接<a class="headerlink" href="#module-scrapy.link" title="永久链接至标题">¶</a></h3>
<dl class="py class">
<dt id="scrapy.link.Link">
<em class="property">class </em><code class="sig-prename descclassname">scrapy.link.</code><code class="sig-name descname">Link</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">url</span></em>, <em class="sig-param"><span class="n">text</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">fragment</span><span class="o">=</span><span class="default_value">''</span></em>, <em class="sig-param"><span class="n">nofollow</span><span class="o">=</span><span class="default_value">False</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/scrapy/link.html#Link"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#scrapy.link.Link" title="永久链接至目标">¶</a></dt>
<dd><p>Link对象表示LinkExtractor提取的链接。</p>
<p>使用下面的锚定标记示例来说明参数：</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">a</span> <span class="n">href</span><span class="o">=</span><span class="s2">&quot;https://example.com/nofollow.html#foo&quot;</span> <span class="n">rel</span><span class="o">=</span><span class="s2">&quot;nofollow&quot;</span><span class="o">&gt;</span><span class="n">Dont</span> <span class="n">follow</span> <span class="n">this</span> <span class="n">one</span><span class="o">&lt;/</span><span class="n">a</span><span class="o">&gt;</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>url</strong> -- 在定位标记中链接到的绝对url。从样本来看，这是 <code class="docutils literal notranslate"><span class="pre">https://example.com/nofollow.html</span></code> .</p></li>
<li><p><strong>text</strong> -- 锚定标记中的文本。从样本来看，这是 <code class="docutils literal notranslate"><span class="pre">Dont</span> <span class="pre">follow</span> <span class="pre">this</span> <span class="pre">one</span></code> .</p></li>
<li><p><strong>fragment</strong> -- url中哈希符号后面的部分。从样本来看，这是 <code class="docutils literal notranslate"><span class="pre">foo</span></code> .</p></li>
<li><p><strong>nofollow</strong> -- 中存在或不存在nofollow值的指示 <code class="docutils literal notranslate"><span class="pre">rel</span></code> 定位标记的属性。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="settings.html" class="btn btn-neutral float-right" title="设置" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="request-response.html" class="btn btn-neutral float-left" title="请求和响应" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        
        &copy; 版权所有 2008–2020, Scrapy developers
      <span class="lastupdated">
        最后更新于 10月 18, 2020.
      </span>

    </p>
  </div>
    
    
    
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
  
 
<script type="text/javascript">
!function(){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.1.0";
analytics.load("8UDQfnf3cyFSTsM4YANnW5sXmgZVILbA");
analytics.page();
}}();

analytics.ready(function () {
    ga('require', 'linker');
    ga('linker:autoLink', ['scrapinghub.com', 'crawlera.com']);
});
</script>


</body>
</html>